//
//  EPMRightTableViewCell.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/5/1.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMRightTableViewCell.h"


@interface EPMRightTableViewCell() 
@property (weak, nonatomic) IBOutlet UIImageView *imgIcon;
@property (weak, nonatomic) IBOutlet UILabel *labDes;
@property (weak, nonatomic) IBOutlet UILabel *labPrice;
@property (weak, nonatomic) IBOutlet UIButton *btnDecrese;
@property (weak, nonatomic) IBOutlet UILabel *labCount;
@property (weak, nonatomic) IBOutlet UILabel *labOldPrice;

@end
@implementation EPMRightTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
    self.model = [EPMGoodsModel new];
}

#pragma mark - 设置界面 -

- (void)setupUI{
    
    [self setLabHiden:[self.labCount.text integerValue]];
    self.labOldPrice.hidden = YES;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(shopCarGoodListChangedNotification:) name:EPMShopCarGoodListChangedNotification object:nil];
    
}
- (void)shopCarGoodListChangedNotification:(NSNotification*)noti{
    [self setLabHiden:self.model.count];
    self.labCount.text = [NSString stringWithFormat:@"%zd",self.model.count];
}


- (IBAction)actionBtnClick:(UIButton *)sender {
//    NSInteger one = sender.tag == 1 ? -1 : 1;
//    NSInteger  count = [self.labCount.text integerValue];
//    count  += one;
    
//    self.labCount.text = [NSString stringWithFormat:@"%zd",count];
//    [self setLabHiden:count];
    
    if (sender.tag == 2){
        CGPoint imgIconCenter = self.imgIcon.center;
        
        CGPoint point = [ self.imgIcon convertPoint:imgIconCenter toView:kWindow];
        [[NSNotificationCenter defaultCenter]postNotificationName:EPMMarketIncreaseGoodNotification object:nil userInfo:@{
                KIncreaseGoodPoint:[NSValue valueWithCGPoint:point],
                KIncreaseGoodImage:self.imgIcon.image,
                KIncreaseGoodsModel: self.model}] ;
    }else if (sender.tag == 1){
        [[NSNotificationCenter defaultCenter] postNotificationName:EPMMarketDecreaseGoodNotification object:nil userInfo:@{
                KDecreaseGoodsModel: self.model}];
    }
    
    if (self.maketRightCellBtnClickBlock){
        self.maketRightCellBtnClickBlock(self.indexpath);
    }
    
    
}

- (void)setModel:(EPMGoodsModel *)model{
    _model = model;
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString: model.img] placeholderImage:[UIImage imageNamed:@"bee"]];
    self.labDes.text = model.long_name;
    self.labPrice.text = model.price;
    [self setLabHiden:model.count];
    self.labCount.text = [NSString stringWithFormat:@"%zd",model.count];
}


- (void)setLabHiden:(NSInteger)num{
    self.labCount.hidden = (num == 0);
    self.btnDecrese.hidden = (num == 0);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:NO];

    // Configure the view for the selected state
}

@end
